
#include <iostream>
#include <vector>

using namespace std;
/*

https://zhuanlan.zhihu.com/p/213853588

*/

class Person {
    int _age;

public:
    Person(int age) : _age(age) {
        cout << "Construct a person." << _age << endl;
    }

    Person(const Person &p) : _age(p._age) {
        cout << "Copy-Construct" << _age << endl;
    }

    Person(const Person &&p) noexcept: _age(p._age) {
        cout << "Move-Construct" << _age << endl;
    }
};


void test_case1() {

    vector<Person> person;
    auto p = Person(1); // >: Construct a person.1
    person.push_back(p); // person.push_back(std::move(p));
    /**
     * >: Copy-Construct1 因为容器扩容，需要把前面的元素重新添加进来，因此需要拷贝
     */
};

void test_case2() {

    vector<Person> person;
    auto p = Person(1); // >: Construct a person.1
    person.emplace_back(move(p)); // >: Move-Construct1
    person.emplace_back(2);
    /**
     * >: Construct a person.2  // 构建一个新的元素
     * >: Move-Construct1       // 拷贝之前的元素过来，这个时候用的是 Person(const Person &&p)
     */
};

class ComplexClass{
public:
  ComplexClass(){
    std::cout<<"Complex Class Constructor"<<std::endl;
  }
  ~ComplexClass(){
    std::cout<<"Complex Class Destructor"<<std::endl;
  }
private:
  //some data member
};

void test_case3() {

    std::vector<ComplexClass> vec;
    vec.push_back(ComplexClass());
}

void test_case4() {

    std::vector<ComplexClass> vec;
    vec.emplace_back();
}


int main() {

    //test_case1();
    //test_case2();
    //test_case3();
    test_case4();

    return 0;
}